home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1996 #6 / Amiga Plus CD - 1996 - No. 06.iso / pd / netz / internet-set.v4.0 / amitcp-4.0 / bin / netdial.rexx < prev    next >
OS/2 REXX Batch file  |  1996-07-24  |  12KB  |  378 lines

  1. /* dialnet.rexx                                                           */
  2. /*                                                                        */
  3. /* Version 1.0, 11 December 1993, by P.J. Rovero                          */
  4. /*         1.2, 19 December 1993                                          */
  5. /*         1.3, 30 December 1993, by K. Raquel Sanborn (raquels@uhunix)   */
  6. /*         1.4, 3  January  1994, Fix reboot Amiga without lose of CSLIP  */
  7. /*         1.5, 5  January  1994, Fix mounting of APIPE:                  */
  8. /*         1.6, 6  January  1994, Add BREAK C support and "PROTECT +S"    */
  9. /*         1.7, 6  January  1994, Add FAILTAT 21 for mount >NIL: APIPE:   */
  10. /*         2.0, 20 December 1994, Redesign by Wes Tatters                 */
  11. /*                                  for AmiTCP 4.0                        */
  12. /*                                Now uses parameter passing instead of   */
  13. /*                                script building.                        */
  14. /*                                Calls dialnet.connect to launch AmiTCP  */
  15. /*         2.1, 1 March 1995,     Configured for AUSNET @ world.net       */
  16. /*                                This service needs Login: before Slip:  */ 
  17. /*                                                                        */      
  18. /*                                                                        */
  19. /*     2.23, 20 Jan 1996,     Adjusted by Kevin Anderson and configured   */
  20. /*                            for Bogomip ISP  andersok@mail.bogo.co.uk   */
  21. /*     3.10, 18 July 1996     Fully auto using .dat file for username etc */
  22. /*                            no editing required uses prefs files to get */
  23. /*                            user and ISP details and save in user.dat,  */
  24. /*                            ISP.dat and Modem.dat plus reconnect added. */ 
  25. /*                                                                        */
  26. /* An ARexx script that will dial a terminal server, connect, determine   */
  27. /* the dynamically assigned IP address, and start the proper components   */
  28. /* of AmiTCP 4.x.  The script uses rexxserdev.library v5.x by Joseph M.   */
  29. /* Stivaletta.                                                            */
  30. /*                                                                        */
  31. /* Inspired by Dave Bolen's REXX/2 SLIPUP.CMD for IBM OS/2 TCPIP 1.2.1    */
  32. /*                                                                        */
  33. /* and AmiTCP_dialup10 by K. Raquel Sanborn                               */
  34. /*                                                                        */
  35. /* ---------------------------------------------------------------------- */
  36.  
  37. /* Define general strings and other initialization stuff                  */
  38.  
  39. say 'Setting Control Variables...'
  40.  
  41. cr         = '0d'x
  42. crlf       = '0d0a'x
  43. lf         = '0a'x
  44.  
  45. say 'Setting User Variables...'
  46.  
  47. dtimeout   = 30                              /* Dial time out in Seconds  */
  48. ctimeout   = 15                              /* Connect time out in Secs  */
  49.  
  50. /* Read user.dat file and get variables */
  51.  
  52. If Open(1,'AmiTCP:bin/user.dat','Read') Then         /* open file for Input */
  53.  
  54.     
  55.   BogoBit$ = ReadLn(1)          /* read file 1 into Bogobit$ variable */
  56.  
  57.   parse var BogoBit$ BogoName'*'BogoWord'*'BogoSpeed  /* split out variables */
  58.  
  59. /* Read Modem.dat file for AT code string */
  60.     
  61. Close(1)                                    
  62.  
  63. If Open(2,'AmiTCP:bin/Modem.dat','Read') Then
  64.  
  65.   ModemSet = ReadLn(2)          /* Read Modem AT code string from file 2 */
  66.  
  67. Close(2)
  68.  
  69. /* Read ISP.dat for Service Provider details */
  70.  
  71. If Open(3,'AmiTCP:bin/ISP.dat','Read') Then
  72.  
  73.   ISPdet = ReadLn(3)            /* Read ISP details from file 3 */
  74.  
  75.   parse var ISPdet host_name'*'host_ip'*'ISPnum'*'Ispslip'*'AskPass
  76.  
  77. Close(3)
  78.  
  79. /*************************      IMPORTANT     *****************************/
  80. /*                                                                        */
  81. /*    PLEASE DO NOT EDIT THIS SCRIPT UNLESS YOU FEEL BRAVE AND KNOW       */
  82. /*    WHAT YOUR DOING all editing is taken care of by the .prefs icons.   */
  83. /*                                                                        */
  84. /************************   USER INFORMATION  *****************************/
  85. /*                                                                        */
  86.  
  87. username   = BogoName||cr 
  88. passwd     = BogoWord||cr 
  89.  
  90. /*                                                                        */
  91. /*********************     ISP's Information   ****************************/
  92.  
  93. dialstr    = 'ATDT'||ISPnum||cr         
  94.  
  95. logprompt  = 'name:'                 
  96. passprompt = 'word:'                 
  97. slipprompt = '*'                     
  98.  
  99. slip_cmd   = ISPslip||cr      
  100. iptype     = 'cslip0'                        /* slip0 for SLIP sites   */
  101.                          /* cslip0 for CSLIP sites */
  102.  
  103. /****************************************************************************/
  104. say 'Setting Modem Variables...'
  105.  
  106.   at_cmd        = 'ATz'||cr
  107.   response      = 'OK'
  108.   modemescape   = '+++'
  109.   modeminit     = ModemSet||cr
  110.   connectstr    = 'CONNECT'
  111.   busystr       = 'BUSY'
  112.   nocarrierstr  = 'NO CARRIER'
  113.   nodialtonestr = 'NO DIALTONE'  
  114.  
  115.  
  116. /**************************************************************************/
  117.  
  118.  
  119. /* Start the required libraries                      */
  120.  
  121.     say 'Opening libraries...'
  122.     say ''
  123.     check = addlib('rexxsupport.library', 0, -30, 0)
  124.     if (check == 0) then say 'rexxsupport library already open...'
  125.  
  126.     check = addlib('rexxserdev.library',  0, -30, 0)
  127.     if (check == 0) then say 'rexxserdev library already open...'
  128.  
  129. /* Open the serial device and talk to the modem                          */
  130.  
  131.     say 'Setting up your serial device...'
  132.     say ''
  133.     serhandle = SerOpen('serial.device', 0)
  134.     check     = SerClear(serhandle)
  135.     check     = SerSetParms( serhandle, BogoSpeed, 8, N, 1, 0 )
  136.  
  137. /* Clean up on "BREAK C" */
  138.  
  139.     buffer = allocmem( 4096 )
  140.     junk   = c2d( buffer )
  141.     signal on break_c
  142.  
  143. /* Initialize Modem                                                     */
  144.  
  145.     say 'Initializing Modem and sending it your AT code string'
  146.     say ''
  147.     result = SerWrite( serhandle, '+++', length( '+++' ) )
  148.     check  = delay(200)
  149.  
  150.     result = SerWrite( serhandle, modeminit, length( modeminit ) )
  151.  
  152.     say 'Waiting for '||response||'  ** If it stops here refer to Modem.help'
  153.     say ''
  154.     call wait_str( response )
  155.  
  156. /* Dial & wait for a connection and the modem status string */
  157.  
  158.     dtime = 0
  159.  
  160.     say 'Dialing your ISP... '
  161.     say ''
  162.     check    = 0
  163.     do forever
  164.     if (check == 0) then
  165.    do
  166.        result = SerWrite( serhandle, dialstr, length( dialstr))
  167.         check = 1
  168.         totalstr = ''
  169.     end
  170.    status   = SerQuery( serhandle )
  171.     parse upper var status valid bytes_read status_bits .
  172.     rcvdstr  = SerRead( serhandle, junk, bytes_read )
  173.     totalstr = totalstr||rcvdstr
  174.  
  175.     dtime = dtime + 1
  176.  
  177.     if ( dtime >= dtimeout ) then
  178.     do
  179.        say Dialer timed out !!!
  180.        result = break_c()
  181.     end
  182.  
  183.     say "Dialing: "||totalstr
  184.  
  185.     test = pos(connectstr, totalstr)
  186.     if (test ~= 0) then leave
  187.  
  188.     test = pos(busystr, totalstr)
  189.     if (test ~= 0) then
  190.     do 
  191.        result = delay( 500 )
  192.        check = 0     
  193.     end
  194.  
  195.     test = pos(nocarrierstr, totalstr)
  196.     if (test ~= 0) then exit 20
  197.  
  198.     test = pos(nodialtonestr, totalstr)
  199.     if (test ~= 0) then exit 20
  200.  
  201.     result   = delay(100)
  202.     end
  203.    
  204.    totalstr = ''
  205.    say ''
  206.    say 'Modem has connected to your ISP...'
  207.    check = delay(50)
  208.    check = SerFlush( serhandle, 'R')
  209.    check = delay(50)
  210.  
  211. /* send CR to wake up terminal server                                      */
  212.  
  213.    say 'Sent CR to wake up your ISP...'
  214.    check = SerWrite( serhandle, cr, length( cr ))
  215.  
  216.         say ''
  217.     say 'Waiting for CSLIP Server... '
  218.     check    = 0
  219.     online   = 0
  220.     totalstr = ''
  221.  
  222.     ctime = 0
  223.  
  224.     do forever
  225.    status   = SerQuery( serhandle )
  226.     parse upper var status valid bytes_read status_bits .
  227.     rcvdstr  = SerRead( serhandle, junk, bytes_read )
  228.     totalstr = totalstr||rcvdstr
  229.  
  230.     say totalstr
  231.  
  232.     ctime = ctime + 1
  233.  
  234.     if ( ctime >= ctimeout ) then 
  235.     do
  236.        say Dialer could not negotiate connection !!!
  237.       result = break_c()
  238.     end
  239.  
  240.     test = pos( 'No response', totalstr )
  241.     if ( test ~= 0 ) then
  242.     do
  243.       say 'Connection failed  ...'
  244.       result = break_c()
  245.     end
  246.  
  247.     test = pos( logprompt, totalstr )
  248.     if ( test ~= 0 ) then
  249.     do
  250.       ctime = 0
  251.       totalstr = ''
  252.       online = online + 1
  253.       say 'Received username prompt...'
  254.       check = SerWrite( serhandle, username, length( username ))
  255.       check = SerRead(  serhandle, junk, length(username))
  256.       say 'Sent your username...'
  257.           say ''
  258.     end
  259.  
  260.     test = pos( passprompt, totalstr )
  261.     if ( test ~= 0 ) then
  262.     do
  263.       ctime = 0
  264.       totalstr = ''
  265.       online = online + 2
  266.       say 'Received password prompt...'
  267.       check = SerWrite( serhandle, passwd, length( passwd ))
  268.       say 'Sent your password...'
  269.     end
  270.  
  271.     test = pos( slipprompt, totalstr )
  272.     if ( test ~= 0 ) then
  273.     do
  274.       ctime = 0
  275.       totalstr = ''
  276.       online = online + 3
  277.       say 'Received Slip command prompt sending Slip Command ...'
  278.       say ''
  279.       check = SerWrite( serhandle, slip_cmd, length( slip_cmd ) )
  280.       check = SerRead( serhandle, junk, length( slip_cmd ) )
  281.     end
  282.  
  283.     if (online == AskPass) then leave   /* checks total of online variable */
  284.  
  285.     result  = delay(100)
  286.     end
  287.  
  288.     totalstr = ''
  289.  
  290.     say 'Connected to your ISP, just waiting for IP addresses...'
  291.  
  292.     address command
  293.     'wait 2 secs'
  294.     call wait_str('address')
  295.     say 'IP address received from Host system...'
  296.     say ''
  297.  
  298. /* Ok, now we have all the data we need to start Cslip           */
  299. /* Close down the serial port but leave the line up (ignore DTR) */
  300.  
  301.     check = SerClose( serhandle )
  302.  
  303.     result = startslip()
  304.     check = freemem(buffer,4096)
  305.  
  306. exit result
  307.  
  308. /* ------------------------------------------------------------- */
  309. /* Exit point for "Break C" or ^C                                */
  310. /* ------------------------------------------------------------- */
  311.  
  312. break_c:
  313.  
  314.     say 'Cleaning up before exit...'
  315.  
  316.     say 'Initializing Modem'
  317.     result = SerWrite( serhandle, '+++', length( '+++' ) )
  318.  
  319.     check  = delay(200)
  320.     result = SerWrite( serhandle, modeminit, length( modeminit ) )
  321.  
  322.     check = SerClose( serhandle )    
  323.     say 'Serial Port closed         Now Click The Close Gadget'
  324.  
  325.     check = freemem(buffer,4096)
  326.  
  327. exit
  328.  
  329. /* ------------------------------------------------------------- */
  330. /* procedure startslip                                           */
  331. /*                                                               */
  332. /* Start and configure AmiTCP for SLIP                           */
  333. /* ------------------------------------------------------------- */
  334.  
  335. startslip:
  336.  
  337.     parse var rcvdstr . 'IP address is ' a '.' b '.' c '.' d '.'.
  338.     slip_ip = a||'.'||b||'.'||c||'.'||d
  339.  
  340. /* Write reconnect ENV variable in case of crash  */
  341.  
  342. Recon$ = slip_ip BogoSpeed
  343.  
  344. If Open(2,'ENVARC:reconnect','Write') Then  
  345.     Do
  346.     WriteLn(2,Recon$) Then                 
  347.     End
  348.     Say 'Ignore these silly error messages there just result codes'
  349. Close(2)
  350.     Say 'Yes these ones'
  351.              
  352.     say 'AmiTCP:bin/netdial.connect starting'
  353.     say ''
  354.     say 'nearly there   Now for the big message thingy'
  355.     say ''
  356.     'AmiTCP:bin/netdial.connect '||host_name||' '||host_ip||' '||slip_ip||' '||amiganame||' '||iptype||' '||BogoSpeed
  357.  
  358. return 0
  359.  
  360.  
  361. /* ------------------------------------------------------------- */
  362. /* Subroutine wait_str  returns when argument string is received */
  363. /* ------------------------------------------------------------- */
  364. wait_str:
  365.  
  366.     teststr = arg(1)
  367.     check = 0
  368.     do until (check ~= 0)
  369.     status = SerQuery( serhandle )
  370.     parse upper var status valid bytes_read status_bits .
  371.     rcvdstr = SerRead( serhandle, junk, bytes_read )
  372.     check   = pos(teststr,rcvdstr)
  373.     test    = delay(50)
  374.     end
  375.  
  376. return
  377.  
  378.